﻿@model IEnumerable<ApplicationBase>
@{
    Layout = "_ControlPanel";
}

<div class="tn-block tnc-ctnborder">
    <div class="tnc-main">
        <div class="tnc-ctn-center">
            <h1>
                <span>应用管理</span>
            </h1>
            <div class="tnc-ctnright-list">
                <div class="tnc-content-manage">
                    <table class="tn-table-grid">
                        <tbody>
                            <tr class="tn-table-grid-header">
                                <td class="tn-border-gray tn-border-bottom tn-text-note">                                    
                                </td>
                                <td class="tn-border-gray tn-border-bottom tn-text-note">
                                    名称
                                </td>
                                <td class="tn-border-gray tn-border-bottom tn-text-note">
                                    描述
                                </td>
                                <td class="tn-border-gray tn-border-bottom tn-text-note">
                                    内容计数
                                </td>
                                <td class="tn-border-gray tn-border-bottom tn-text-note">
                                    是否启用
                                </td>
                                <td class="tn-border-gray tn-border-bottom tn-text-note">
                                    操作
                                </td>
                            </tr>
                            @foreach (var application in Model)
                            {
                                IEnumerable<ApplicationStatisticData> statisticDatas = null;
                                try
                                {
                                    statisticDatas = DIContainer.ResolveNamed<IApplicationStatisticDataGetter>(application.ApplicationKey).GetStatisticDatas();
                                }
                                catch
                                {
                                    continue;
                                } 
                                <tr class="tn-table-grid-row">
                                    <td class="tn-border-gray tn-border-bottom tn-width-icon1">
                                    <span class="tn-icon tn-icon-@application.ApplicationKey.ToLower()"></span>                                 
                                    </td>
                                    <td class="tn-border-gray tn-border-bottom tn-width-category tn-nowrap">
                                    @application.Config.ApplicationName
                                    </td>
                                    <td class="tn-border-gray tn-border-bottom tn-width-auto">
                                    @application.Description
                                    </td>
                                    <td class="tn-border-gray tn-border-bottom tn-nowrap">
                                        @foreach (var statisticData in statisticDatas)
                                        {
                                            <p>@statisticData.Name: @statisticData.Value</p>
                                        }
                                    </td>
                                    <td class="tn-border-gray tn-border-bottom tn-nowrap">                                    
                                    <span class="tn-icon-colorful tn-icon-colorful-@(application.IsEnabled ? "pass" : "stop")"></span>                                                                        
                                    </td>
                                    <td class="tn-border-gray tn-border-bottom tn-width-action1 tn-nowrap">
                                    @if (application.IsLocked)
                                    { 
                                        <span class="tn-text-note" title="锁定应用不允许禁用">禁用</span>
                                    }
                                    else
                                    {
                                        <a name="changeEnableStatusButton" class="tn-action" href="@SiteUrls.Instance().SetApplicationStatus(application.ApplicationId)" data-isenabled="@application.IsEnabled.ToString().ToLower()">
                                            <span class="tn-action-text">@(application.IsEnabled ? "禁用" : "启用")</span></a>
                                    }
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("a[name='changeEnableStatusButton']").click(function (e) {
            var self = $(this);
            var isEnabled = self.data("isenabled");
            $.post(self.attr("href"), { isEnabled: !isEnabled }, function (data) {
                if (data.MessageType >= 0) {
                    self.data("isenabled", !isEnabled);
                    self.text(isEnabled ? "启用" : "禁用");
                    self.closest("tr").find("span.tn-icon-colorful-pass,span.tn-icon-colorful-stop").toggleClass("tn-icon-colorful-pass").toggleClass("tn-icon-colorful-stop");
                }
                art.dialog.tips(data.MessageContent, 2, data.MessageType);                
            });
            return false;
        });
    });
</script>
